package com.leetcodehot.problems;

public class problems713 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int n = nums.length;
        int left = 0;
        int prod = 1;
        int res = 0;
        if (k <= 1) return 0;
        //此题需要明确的是right只计算right为右端点的满足条件的部分
        for (int right = 0; right < n; right++) {
            //到right
            prod *= nums[right];
            while (prod >= k) {
                prod /= nums[left];
                left++;
            }
            res += right - left + 1;
        }
        return res;
    }
}
